package com.cjjs.jsf.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.cjjs.jsf.service.WXSpellingService;
import com.cjjs.jsf.util.AjaxReturnVO;

@RestController
@RequestMapping(value="/wx-spell")
public class WXSpellManageController {
	
	@Autowired
	private WXSpellingService wxSpellService;
	
	
	@GetMapping(value="/valitIsSpelling")
	public AjaxReturnVO valitSpell(@RequestParam(name="openId")String openId,
			@RequestParam(name="spelId") String spelId) {
		
		AjaxReturnVO vo = new AjaxReturnVO();
		
		try {
			vo.setOk(true);
			vo.setMsg(this.wxSpellService.valitSpell(spelId,openId)?"y":"n");
		} catch (Exception e) {
			e.printStackTrace();
			vo.setFail(vo, e.getMessage()==null?"" : e.getMessage());
		}
		
		return vo;
	}
	
	@GetMapping("/spelling")
	public AjaxReturnVO spelling(@RequestParam(name="openId")String openId,
			@RequestParam(name="spelId") String spelId) {
		
		AjaxReturnVO vo = new AjaxReturnVO();
		
		try {
			vo.setOk(true);
			this.wxSpellService.saveOrUpdate(openId,spelId);
		} catch (Exception e) {
			vo.setFail(vo, e.getMessage());
			e.printStackTrace();
		}
		
		return vo;
	}

}
